package asteroids.model.programs.parsing.expressions;

import java.util.Map;

import asteroids.model.Ship;
import asteroids.model.programs.parsing.types.DoubleLiteral;
import asteroids.model.programs.parsing.types.Type;

/**
 * A class of multiplication expressions.
 * A multiplication expression involves a multiplication operation between a left-hand operand and a right-hand operand.
 * 
 * @author Thijs Dieltjens - Wim Konings
 * @version 2.0
 */
public class MultiplyExpr extends ArithmeticExpr {

	public MultiplyExpr(Expression e1, Expression e2,int line,int column) {
		super(e1, e2,line,column);
	}

	@Override
	public Type eval(Ship ship, Map<String, Type> globals) {
		Type t1=getLeftOperand().eval(ship, null);
		Type t2=getRightOperand().eval(ship, null);

		if(t1 instanceof DoubleLiteral && t2 instanceof DoubleLiteral) {
			return new DoubleLiteral(((DoubleLiteral) t1).getValue() * ((DoubleLiteral) t2).getValue());
		}
		return new DoubleLiteral();
	}
}
